package 
{
	import controller.ControllerManager;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import model.ModelManager;
	import view.ressources.GraphicRessourcesManager;
	import view.ViewManager;
	import flash.display.StageDisplayState;
	
	/**
	 * ...
	 * @author Anthony
	 */
	public class Main extends Sprite
	{
		
		public function Main() : void 
		{
			if (stage) 
				init();
			else 
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e : Event = null) : void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// stage settings
			stage.align 		= StageAlign.TOP_LEFT;
			stage.scaleMode 	= StageScaleMode.NO_SCALE;
			//stage.displayState 	= StageDisplayState.FULL_SCREEN;
			// start
			ModelManager.self.addEventListener(ModelManager.LOADED, modelLoaded);
			ModelManager.self.init();			
		}
		
		private function modelLoaded(e : Event) : void
		{
			ModelManager.self.removeEventListener(ModelManager.LOADED, modelLoaded);
			GraphicRessourcesManager.self.addEventListener(GraphicRessourcesManager.LOADED, graphicRessourcesLoaded);
			GraphicRessourcesManager.self.init();			
		}
		
		private function graphicRessourcesLoaded(e : Event) : void
		{
			GraphicRessourcesManager.self.removeEventListener(GraphicRessourcesManager.LOADED, graphicRessourcesLoaded);
			addChild(ViewManager.self.graphic);
			ViewManager.self.init();
			ControllerManager.self.init();
		}
	}
	
}